# Euler Problem 5
# What is the smallest number that is evenly divisible by all of the numbers from 1 to 20?
maxnum = 20

import math
#################################
cycles = 50000
cycles = 1
import time
c1 = time.clock()
for x in xrange(0xFFFFF): pass
for i in range(cycles):
    answer = 0
#################################
### program calculation start ###
#################################

#    done = 0
#    while not done:

    # calculate primes up to maximum number
    factorarray = []
    for checkprime in range(2, maxnum):
        checking = 1
        againstfactor = 2
        while checking:
            if checkprime == againstfactor:
                factorarray.append([checkprime,0])
                checking = 0
            else:                                
                if checkprime % againstfactor == 0:
                    checking = 0
                else:
                    againstfactor += 1

    #print factorarray

    for factorme in range(2,maxnum):
        primeindex = 0
        numfactors = 0
        
        while factorme != 1:
            
            if factorme % factorarray[primeindex][0] == 0:
                factorme = factorme / factorarray[primeindex][0]
                numfactors += 1
                
                if (factorme % factorarray[primeindex][0] != 0) and \
                   (factorarray[primeindex][1] < numfactors):
                    factorarray[primeindex][1] = numfactors
            else:
                primeindex += 1
                numfactors = 0

    print factorarray                

    answer = 1
    for factorpairs in factorarray:
        answer *= factorpairs[0] ** factorpairs[1]
    
#################################
###  program calculation end  ###
#################################
c2 = time.clock()
if cycles > 1: print "Time spent is %.2f ms" % ((c2-c1)*1000/cycles)
#################################
        
print 'The answer to Problem #5 is >>', answer, '<<'

        